package br.com.news.business;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import br.com.news.business.utils.GenericBusiness;
import br.com.news.utils.business.exception.BusinessException;
import br.com.news.utils.business.interfaces.IRespostaEnqueteBusiness;
import br.com.news.utils.database.beans.RespostaEnqueteBean;
import br.com.news.utils.database.exception.DataBaseServiceException;
import br.com.news.utils.database.interfaces.IRespostaEnqueteServiceDb;

@Named
public class RespostaEnqueteBusiness extends GenericBusiness implements IRespostaEnqueteBusiness{

	@Inject
	private IRespostaEnqueteServiceDb respostaEnqueteServiceDb;
	
	@Override
	public List<RespostaEnqueteBean> findAll() throws BusinessException {
		try {
			return respostaEnqueteServiceDb.findAll();
		} catch (DataBaseServiceException e) {
			throw new BusinessException(e);
		}
	}

	@Override
	public void save(RespostaEnqueteBean respostaEnquete) throws BusinessException {
		try {
			respostaEnqueteServiceDb.save(respostaEnquete);
		} catch (DataBaseServiceException e) {
			throw new BusinessException("Erro ao tentar salvar resposta", e);
		}	
	}

	@Override
	public List<RespostaEnqueteBean> resultVoteXml(long idEnquete) throws BusinessException {
		try {
			return respostaEnqueteServiceDb.resultVoteXml(idEnquete);
		} catch (DataBaseServiceException e) {
			throw new BusinessException(e);
		}
	}
}
